#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <image.h>
#include <pnmfile.h>
#include <imconv.h>
#include "regionGrowing.h"

int main(int argc, char **argv) {
  if (argc != 3) {
    fprintf(stderr, "usage: %s input(ppm pgm) output(ppm)\n", argv[0]);
    return 1;
  }
  
  printf("Loading input image.\n");  
	
	image<rgb> *input;

  if (strstr(argv[1], ".pgm\0")!=NULL){
		image<uchar> *imGray = loadPGM(argv[1]);
		input = imageGRAYtoRGB(imGray);
	}
	else
	  input = loadPPM(argv[1]);
	
  printf("Processing....\n");
  int regNum; 
  image<rgb> *seg = segment_image(input, &regNum);
  savePPM(seg, argv[2]);

  printf("Got %d regions\n", regNum);
  printf("Done!\n");

  return 0;
}

